package app.web.admin.domain.ao;

import app.config.Config;
import com.gitee.feizns.quickstart.validation.Verifiable;
import com.gitee.feizns.quickstart.web.decrypt.DecryptionAlgorithm;
import lombok.Data;

import javax.validation.constraints.NotBlank;

/**
 * 登录请求参数
 * @author feizns
 * @since 2025/4/9
 */
@Data
public class LoginAo implements Verifiable {

    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空.")
    private String mobile;

    /**
     * 密码
     */
    @NotBlank(message = "密码不能为空.")
    private String password;

    /**
     * 验证码
     */
    private String code;

    @Override
    public boolean validate() {
        if ( Config.rsaAutomaticDecryption() ) {
            this.mobile = DecryptionAlgorithm.instance().decrypt(mobile);
            this.password = DecryptionAlgorithm.instance().decrypt(password);
            this.code = DecryptionAlgorithm.instance().decrypt(code);
        }
        return Verifiable.super.validate();
    }

}
